<%@page import="Logic.AppointmentModify_BLL"%>
<%@page import="servlet.AppttypeDropdown"%>
<%@page import="Logic.Authorizer"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%
	if (session.getAttribute("name") == null) {
		response.sendRedirect("login.jsp");
	} else {
		if (Authorizer.checkRole("1", session.getAttribute("role")
				.toString()) || Authorizer.checkRole("3", session.getAttribute("role").toString()) || (session
						.getAttribute("role").equals("2"))) {

		}
		else
		{
			response.sendRedirect("nopermission.jsp");
						
		}
	}
%>


<!-- Declare the first header -->
<jsp:include page="t_header.jsp" />


<jsp:include page="header.html" />
<!-- Declare sidebar -->
<jsp:include page="t_sidebarappointment.jsp" />>

<!-- Main Content -->
<section id="main" class="column">
	<%
		String apptName = "";
		String apptResponsibility = "";
		if (request.getParameter("id") != null)
		{
			try
			{
				apptName = AppointmentModify_BLL.getNamebyID(request
						.getParameter("id"));
				apptResponsibility = AppointmentModify_BLL
						.getResponsibilitybyID(request.getParameter("id"));
			}
			catch (Exception e)
			{

			}
		}

		if (request.getParameter("error") != null)
		{
			if (request.getParameter("error").equals("1"))
				out.print("<h4 class='alert_error'>The operation was not completed successfully.</h4>");
			else if (request.getParameter("error").equals("2"))
				out.print("<h4 class='alert_error'>Error - Please choose a different appointment name.</h4>");
			else if (request.getParameter("error").equals("-1"))
				out.print("<h4 class='alert_success'>Operation completed successfully.</h4>");
		}
	%>
	<%
		if (request.getParameter("action") != null)
		{
			if (request.getParameter("action").equals("d"))
				out.print("<h4 class='alert_warning'>Please confirm your deletion of &quot;"
						+ apptName + "&quot;.</h4>");
			else if (request.getParameter("action").equals("e"))
				out.print("<h4 class='alert_info'>You are now editing &quot;"
						+ apptName + "&quot;.</h4>");
		}
	%>

	<%
		if (request.getParameter("action") == null
				|| (!request.getParameter("action").equals("d") && !request
						.getParameter("action").equals("e"))
				|| request.getParameter("id") == null)
		{
	%>
	<article class="module width_3_quarter">
		<form action="AppttypeModify" method="POST">
			<header>
				<h3>Choose Appointment Type</h3>
			</header>
			<div class="module_content">
				<fieldset style="width: 100%; float: left; margin-right: 3%;">
					<!-- to make two field float next to one another, adjust values accordingly -->
					<label>Appointment Type</label> <select name="staff"
						style="width: 92%;">
						<%
							AppttypeDropdown rt = new AppttypeDropdown(out);
								rt.doGet(request, response);
						%>
					</select>
				</fieldset>
				<div class="clear"></div>
			</div>
			<footer>
				<div class="submit_link">
					<input type="submit" name="submit" value="Edit" class="alt_btn"> <input
						type="submit" name="submit" value="Delete" class="alt_btn">
				</div>
			</footer>
		</form>
	</article>
	<!-- end of post new article -->
	<%
		}
	%>

	<%
		if (request.getParameter("action") != null
				&& request.getParameter("action").equals("d")
				&& request.getParameter("id") != null)
		{
	%>
	<article class="module width_3_quarter">
		<form action="DeleteAppointment" method="POST">
			<header>
				<h3>Confirm Delete?</h3>
			</header>
			<div class="module_content">
				<h4>Are you sure you want to delete this appointment type? You
					cannot undo this action!</h4>
					<input name="id" type="hidden" value="<%=request.getParameter("id")%>"/>
				<div class="clear"></div>
			</div>
			<footer>
				<div class="submit_link">
					<input type="submit" name="ahlama1" value="Confirm" class="alt_btn">
					<input type="submit" name="ahlama1" value="Cancel" class="alt_btn">
					
				</div>
			</footer>
		</form>
	</article>
	<%
		}
	%>
	<!-- end of post new article -->
	<div class="clear"></div>

	<%
		if (request.getParameter("action") != null
				&& request.getParameter("action").equals("e")
				&& request.getParameter("id") != null)
		{
	%>
	<article class="module width_3_quarter">
		<form action="EditAppointment" method="POST">
			<header>
				<h3>Edit Appointment Type</h3>
			</header>
			<div class="module_content">
				<fieldset>
					<label>Appointment Name</label> <input type="text" maxlength="70"
						name="apt_name" value="<%=apptName%>">
				</fieldset>
				<fieldset>
					<label>Roles and Responsibilities</label>
					<textarea name="apt_responsibility" rows="12"><%=apptResponsibility%></textarea>
				</fieldset>
				<input name="id" type="hidden" value="<%=request.getParameter("id")%>"/>
			</div>
			<footer>
				<div class="submit_link">
					<input type="submit" name="ahlama" value="Save" class="alt_btn">
						
					
					 <input type="submit" name="ahlama" value="Cancel" class="alt_btn">
					
					
				</div>
			</footer>
		</form>
	</article>
	<%
		}
	%>
	<!-- end of post new article -->
	<div class="spacer"></div>
</section>

<!-- Declare closing tags -->
<jsp:include page="t_footer.jsp" />